#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@Project : pythonProject
@File : redis-scan.py
@Author : 万能小魏
@Time : 2024-09-23 10:17
@脚本说明 :

"""

import argparse
import threading

import redis_exp

# 创建解析器对象
parser = argparse.ArgumentParser(description="天眼综合漏扫系统")
# 创建子命令解析器
subparsers = parser.add_subparsers(dest="command", help="子系统选择")

# 创建 redis-scan子命令
parser_redis_scan = subparsers.add_parser("redis", help="Redis 扫描")
parser_redis_scan.add_argument("-H", "--host", type=str, required=True, help="Redis 主机")
parser_redis_scan.add_argument("-p", "--port", type=int, default=6379, help="Redis 端口")
parser_redis_scan.add_argument("-f", "--file", type=str, required=True, help="Redis 密码本路径")
parser_redis_scan.add_argument("-k", "--key", type=str, default=None, help="公钥路径")

# 创建 mysql-scan 子命令
# ...

args = parser.parse_args()


def redis_scan():
    thread_list = []
    with open(file=f"{args.file}", mode="r", encoding="utf-8") as p:
        for passwd in p.readlines():
            t = threading.Thread(target=redis_exp.san_redis,
                                 args=(args.host, args.port, passwd.strip(), args.key))
            t.start()
            thread_list.append(t)
    for t in thread_list:
        t.join()


def run():
    if args.command == "redis":
        redis_scan()

def banner():
    banner_text = """
        _____          _ _      _____                 
        |  __ \        | (_)    / ____|                
        | |__) |___  __| |_ ___| (___   ___ __ _ _ __  
        |  _  // _ \/ _` | / __|\___ \ / __/ _` | '_ \ 
        | | \ \  __/ (_| | \__ \____) | (_| (_| | | | |
        |_|  \_\___|\__,_|_|___/_____/ \___\__,_|_| |_|
    """
    print(banner_text)
if __name__ == '__main__':
    banner()
    run()
